package top.lixunda.ecommerce.server.good.feign;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.business.api.entity.dto.PageDTO;
import top.lixunda.ecommerce.server.good.api.entity.db.StoreDO;
import top.lixunda.ecommerce.server.good.api.entity.dto.StoreInfoQueryDTO;
import top.lixunda.ecommerce.server.good.api.feign.IFeignStoreController;
import top.lixunda.ecommerce.server.good.service.IStoreService;

import java.util.List;

/**
 * 店铺信息查询接口
 *
 * @author lixunda
 * @version time:2020/4/18 22:00
 */
@Slf4j
@RestController
public class FeignStoreController extends BaseController
        implements IFeignStoreController {

    private final IStoreService storeService;

    @Autowired
    public FeignStoreController(IStoreService storeService) {
        this.storeService = storeService;
    }

    /**
     * 根据id查询店铺信息，必须存在，否则抛出异常
     *
     * @param id 店铺id，不能为空，大于零的数字
     * @return 店铺基本数据
     */
    @Override
    public MessageObject<StoreDO> queryStoreInfoById(Integer id) {
        StoreDO storeDO = storeService.queryStoreInfoById(id);
        return getSuccessMessageObject("获取店铺数据成功", storeDO);
    }

    /**
     * 根据多个id查询店铺数据
     *
     * @param ids 店铺id数组，单个id为大于零的数字
     * @return 店铺基本数据列表，返回查询到的店铺信息，没查到不会抛出异常
     */
    @Override
    public MessageObject<List<StoreDO>> queryStoreInfoByIds(List<Integer> ids) {
        List<StoreDO> storeDO = storeService.queryStoreInfoByIds(ids);
        return getSuccessMessageObject("获取店铺数据成功", storeDO);
    }

    /**
     * 条件分页查询店铺基本信息
     *
     * @param pageDTO 分页条件和查询条件
     * @return 分页数据
     */
    @Override
    public MessageObject<Page<StoreDO>> queryStoreInfoByPageWrapper(PageDTO<StoreDO, StoreInfoQueryDTO> pageDTO) {
        IPage<StoreDO> storeDO = storeService.queryAdminInfoByPageWrapper(pageDTO);
        return getSuccessMessageObject("获取店铺数据成功", (Page<StoreDO>) storeDO);
    }
}
